;-------------------------------------------------------------LICENSE--------------------------------------------------------------;
;                                                                                                                                  ;
;The MAP code is written in Fortran language for magnetohydrodynamics (MHD) calculation with the adaptive mesh refinement (AMR)    ;
;and Message Passing Interface (MPI) parallelization.                                                                              ;
;                                                                                                                                  ;
;Copyright (C) 2012                                                                                                                ;
;Ronglin Jiang                                                                                                                     ;
;rljiang@ssc.net.cn                                                                                                                ;
;585 Guoshoujing Road. Pudong, Shanghai, P.R.C. 201203                                                                             ;
;                                                                                                                                  ;
;This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License         ;
;as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.             ;
;                                                                                                                                  ;
;This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of    ;
;MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.                        ;
;                                                                                                                                  ;
;You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software     ;
;Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.                                                   ;
;                                                                                                                                  ;
;-------------------------------------------------------------LICENSE--------------------------------------------------------------;

; Purpose
;    Calculate 3d array by a given one dimensional array
;   
; Inputs
;    One dimensional array
;   
; Outputs
;    Returns 3d replicate array
;
; Notes
;    The array will be replicated in the given direction
;
; Histroy
;    2010-05-24 written by R. L. Jiang at kwasan observatory
;
function repli3d,arr1d,dir=dir,nx=nx,ny=ny,nz=nz

on_error,2

if n_elements(arr1d) eq 0 then begin
   print,' No input one dimensial array.'
   retall
endif
if n_elements(dir) eq 0 then begin
   print,' No input direction.'
   retall
endif
if n_elements(nx)+n_elements(ny)+n_elements(nz) eq 0 then begin
   print,' No input grid point.'
   retall
endif

case size(arr1d, /tname) of 
  'BYTE':arr3d=bytarr(nx,ny,nz)
  'INT':arr3d=intarr(nx,ny,nz)
  'UINT':arr3d=uintarr(nx,ny,nz)
  'LONG':arr3d=lonarr(nx,ny,nz)
  'ULONG':arr3d=ulonarr(nx,ny,nz)
  'LONG64':arr3d=lon64arr(nx,ny,nz)
  'ULONG64':arr3d=ulon64arr(nx,ny,nz)
  'FLOAT':arr3d=fltarr(nx,ny,nz)
  'DOUBLE':arr3d=dblarr(nx,ny,nz)
   else:begin
      print,' Not a supported type.'
      retall
   end
endcase

if strlowcase(dir) eq 'x' then   $
for i=0,nx-1 do arr3d[i,*,*]=replicate(arr1d[i],ny,nz)
if strlowcase(dir) eq 'y' then $
for i=0,ny-1 do arr3d[*,i,*]=replicate(arr1d[i],nx,nz)
if strlowcase(dir) eq 'z' then $
for i=0,nz-1 do arr3d[*,*,i]=replicate(arr1d[i],nx,ny)

return,arr3d

end